package ink.tiptop.controller;

import ink.tiptop.persist.domain.entity.ZjfPubKeyEntity;
import ink.tiptop.dto.req.base.key.AddZjfPubKeyEntityRequest;
import ink.tiptop.dto.req.base.key.DeleteZjfPubKeyEntityRequest;
import ink.tiptop.dto.req.base.key.QueryZjfPubKeyEntityRequest;
import ink.tiptop.dto.req.base.key.UpdateZjfPubKeyEntityRequest;
import ink.tiptop.common.domain.rsp.Response;
import ink.tiptop.service.ZjfPubKeyService;
import ink.tiptop.utils.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 公钥信息表(ZjfPubKey)表控制层
 *
 * @author makejava
 * @since 2020-07-20 16:31:45
 */
@Api("服务器公钥信息API")
@RestController
@RequestMapping("zjfPubKey")
@Slf4j
public class PubKeyController {
    /**
     * 服务对象
     */
    @Resource
    private ZjfPubKeyService zjfPubKeyService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("单一查询公钥信息")
    @GetMapping("selectOne")
    public ZjfPubKeyEntity selectOne(Integer id) {
        return this.zjfPubKeyService.queryById(id);
    }

    /**
     * 通过实体类查询列表数据
     *
     * @param request 实例对象
     * @return 单条数据
     */
    @ApiOperation("查询列表信息")
    @PostMapping("list")
    @ResponseBody
    public Response list(@RequestBody @Valid QueryZjfPubKeyEntityRequest request) {
        log.info("查询列表信息,入参:{}", JSON.toJSONString(request));
        return this.zjfPubKeyService.list(request);
    }

    @ApiOperation("更新公钥信息")
    @PostMapping("update")
    @ResponseBody
    public Response update(@RequestBody @Valid UpdateZjfPubKeyEntityRequest request) {
        log.info("更新公钥信息,入参:{}", JSON.toJSONString(request));
        return this.zjfPubKeyService.update(request);
    }

    @ApiOperation("批量删除公钥信息")
    @PostMapping("delete")
    @ResponseBody
    public Response delete(@RequestBody @Valid DeleteZjfPubKeyEntityRequest request) {
        log.info("批量删除公钥信息,入参:{}", JSON.toJSONString(request));
        return this.zjfPubKeyService.delete(request);
    }


    /**
     * @param request 主键
     * @return 单条数据
     */
    @ApiOperation("添加公钥信息")
    @PostMapping("add")
    @ResponseBody
    public Response add(@RequestBody @Valid AddZjfPubKeyEntityRequest request) {
        log.info("添加公钥信息,入参:{}", JSON.toJSONString(request));
        return this.zjfPubKeyService.add(request);
    }


}